KitePlayerPictureInPicture

Puts a KitePlayer in the small floating window, and lets that window drive it, on iOS and macOS.

The system offers this only to a player that draws into a sample buffer display layer, which is what SampleBufferVideoRenderer in the output module produces. Pair the view with that renderer first, then build one of these over the same layer. On macOS, an AppKitWindow built with the sample buffer surface hosts such a layer.

What this keeps in step, so the window never shows a stale state:

  • The play button and the range. The window reads them again whenever the player's status, duration or seekability changes. A source that cannot seek hides the skip buttons.

  • The progress bar. The window reads the layer's clock, so this gives the layer a clock and keeps it at the player's position and speed through play, pause, seek and speed changes.

  • active, from the window's own reports that it opened and closed.

Building it can fail for a reason that is not an error: a device that does not offer the feature. createOrNull answers null rather than throwing at the moment a viewer is trying to leave the app.

On iOS the application still declares the background audio capability itself; without it the window appears and freezes as soon as the app is no longer on screen. Pass this object to attachBackgroundHandling in kiteplayer, so video keeps playing in the window while the app is away.

Use every member from the main thread.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val active: StateFlow<Boolean>

True from the moment the window has opened until it has closed, or failed to open.

Link copied to clipboard

True while the small window is on screen, as the controller reports it now.

Link copied to clipboard

True when the system is willing right now. It can change with the device's state.

Link copied to clipboard
var onRestoreRequested: (done: (Boolean) -> Unit) -> Unit?

Called when the viewer asks to go back to the app from the window.

Link copied to clipboard

Whether the window opens by itself when the viewer leaves the app while playing.

Functions

Link copied to clipboard
open override fun close()

Closes the window if it is open and lets go of the layer. Safe to call twice.

Link copied to clipboard
fun start()

Asks for the window. Does nothing when the system is not willing; check isPossible.

Link copied to clipboard
fun stop()

Puts the picture back in the app.